<?php
namespace app\admin\controller;

use think\Db;
use app\admin\model\DepartmentModel;
class Gis extends Base{
	public function _initialize(){
		$cfg = [
			'ak' => DB::name('api_cfg')->where('remark','baidumap_ak_jsapi')->value('val'),
			'url' => DB::name('api_cfg')->where('remark','baidumap_url_jsapi')->value('val'),
			'version' => DB::name('api_cfg')->where('remark','baidumap_version_jsapi')->value('val'),
			'centerName' => "大理",
		];
		$this->assign([
			'cfg' => $cfg
		]);
	}

	public function index(){
		return $this->fetch();
	}

	/**
	 * [地图加点工具]
	 */
	public function map_addpoint_tool(){
		return $this->fetch();
	}

	/**
	 * [地图点聚合工具]
	 */
	public function map_polymerize_tool() {
		return $this->fetch();
	}

	/**
	 * [地图正反解析工具]
	 */
	public function map_analyze_tool() {
		return $this->fetch();
	}

	/**
	 * [地图自定义控件和点图标工具]
	 */
	public function map_diy_tool() {
		return $this->fetch();
	}

	/**
	 * [地理信息分布]
	 */
	public function distribution() {
		$DepartModel = new DepartmentModel();
		$departs = $DepartModel->getCanSeeDepart(session('id'));
		$departs = $this->arr2tree($departs);
		$departs = $this->getNameByTree($departs);

		$department = DB::name('department')->alias('depart')
					->join('role role','depart.id = role.department_id')
					->join('user user','user.role_id = role.id')
					->where('user.id',session('id'))
					->field('depart.name,depart.id')->find();
		$this->assign([
			'departs' => $departs,
			'default_depart_id' => $department['id'],
			'default_s_time' => strtotime("-3 month")."000",
			'default_e_time' => strtotime("-1 month")."000",
		]);
		return $this->fetch();
	}
	/**
	 * [地图描点总计]
	 */
	public function distribution_gis() {
		$this->assign([
			'depart_id' => input("get.depart_id"),
			's_time' => input("get.s_time"),
			'e_time' => input("get.e_time"),
			'type' => input("get.type")
		]);
		return $this->fetch();
	}
	/**
	 * []
	 */
	public function getPointList() {
		$param = input("post.");
		$where = [];
		if($param['s_time'] && $param['e_time']){
			$where['c_time'] = ['between',[$param['s_time'],$param['e_time']]];
		}else{
			$where['c_time'] = ['between',[strtotime("-3 month"),strtotime("-1 month")]];
		}
		if($param['depart_id']){
			$where['depart_id'] = $param['depart_id'];
		}
		if($param['type']){
			$where['type'] = $param['type'];
		}
		$list = DB::name('map_gis')->where($where)->select();
		for($i=1;$i<6;$i++){
			$count[$i] = DB::name('map_gis')->where($where)->where('type',$i)->count();
		}
		return ['code'=>1,'msg'=>'ok','data'=>$list,'count'=>$count];
	}
}
